package backtrace;

import java.util.ArrayList;
import java.util.List;

public class leetcode78子集 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        int length = nums.length;
        dfs(result, list, nums, length, 0);
        return result;
    }

    public void dfs(List<List<Integer>> result, List<Integer> list, int[] nums, int length, int count) {
        if (count == length) {
            result.add(new ArrayList<>(list));
        } else {
            list.add(nums[count]);
            dfs(result, list, nums, length, count + 1);
            list.remove(list.size() - 1);
            dfs(result, list, nums, length, count + 1);
        }
    }
}
